package com.panopset.gui.container;

import static com.panopset.Util.x;

public class PanIntField extends PanNumericOnlyField {

    private static final String LONG_FIELD_MESSAGE = x("Please enter an integer value, no decimal places.");

    public Integer getIntValue() {
        return Integer.parseInt(getValue());
    }

    public PanIntField(int cols, String borderTitle, String toolTipText,
            String defaultValue) {
        super(cols, borderTitle, toolTipText, defaultValue);
        addValidator(new Validator() {

            @Override
            public String validate(String value) {
                if (value == null) {
                    return LONG_FIELD_MESSAGE;
                }
                try {
                    Integer.parseInt(value);
                } catch(NumberFormatException ex) {
                    return LONG_FIELD_MESSAGE;
                }
                return null;
            }
        });
    }
}
